package zunge.pmp;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.HashMap;

public class ClusteringPrep {
	public static void main(String[] args){
		
		String inputFile = "/usr0/home/bliu1/BinWork/Program/mysql/tmp/pmp_uf.txt";
		String outputFile = "/usr0/home/bliu1/Desktop/pmp_uf_matrix.txt";
		try{
			BufferedReader br = new BufferedReader(new FileReader(inputFile));
			BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));
			String line; int u_id; int f_id; double rate;
			
			int cur_u_id = -1;
			double[] rates = new double[20];Arrays.fill(rates, 0);
			
			while((line=br.readLine())!=null){
				String[] frags = line.split("\t");
				u_id = Integer.parseInt(frags[0]);
				f_id = Integer.parseInt(frags[1]);
				rate = Double.parseDouble(frags[2]);
				
				if(cur_u_id!=u_id){
					if(cur_u_id!=-1){
						for(int i = 0;i < 19;++i){bw.write(rates[i]+" ");} 
						bw.write(rates[19]+"\n");
					}
					cur_u_id = u_id;
					Arrays.fill(rates, 0);
				}
				rates[f_id-1]=rate;
			}
			for(int i = 0;i < 19;++i){bw.write(rates[i]+"\t");} 
			bw.write(rates[19]+"\n");
			
			br.close();
			bw.close();
			
		}catch(Exception e){e.printStackTrace();}
	}
}
